package com.xll.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xll.entity.Hotel;
import com.xll.entity.Order;
import com.xll.entity.Remark;
import com.xll.mapper.OrderMapper;
import com.xll.service.OrderService;
import com.xll.utils.PageResult;
import com.xll.utils.QueryInfo;
import com.xll.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class OrderServiceImpl  implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public Result insert(Order order) {
        orderMapper.insert(order);
        return  Result.success("订单信息插入成功");
    }

    @Override
    public Result findByUserId(Long userId) {
        if(userId==null){
            return  Result.fail("请传入id");
        }
        List<Order> byUserId = orderMapper.findByUserId(userId);
        return Result.success("获取订单信息成功",byUserId);
    }

    @Override
    public Result findPage(QueryInfo queryInfo) {
        PageHelper.startPage(queryInfo.getPageNumber(), queryInfo.getPageSize());
        Page<Order> page = orderMapper.findPage(queryInfo.getQueryString());
        return Result.success("订单信息查询成功", new PageResult(page.getTotal(), page.getResult()));
    }
}
